package com.example.qm;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {
	private Button tz;
	private Handler myHandler;
	private int i = 5;
	private int flag = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		tz = (Button) findViewById(R.id.tz);
		tz.setOnClickListener(new MyListener());

		myHandler = new Handler() {

			public void handleMessage(Message msg) {

				super.handleMessage(msg);
				if (msg.what == 0x12) {
					if (i >= 0) {

						i--;
					}
					if (i == -1 || flag == 1) {
						finish();
						startActivity(new Intent(MainActivity.this,
								da4Activity.class));
						i = -2;

					}
				}
			}

		};

		new Thread(new Runnable() {
			public void run() {
				try {
					while (i >= 0) {
						Message msg = new Message();
						msg.what = 0x12;
						myHandler.sendMessage(msg);
						Thread.sleep(1000);
					}
				} catch (Exception e) {
					e.printStackTrace();
				}

			};
		}).start();

	}

	private class MyListener implements OnClickListener {
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.tz:
				flag = 1;

				break;
			}
		}

	}

}
